package com.googlecode.afdbaccess.web.portal.webcontent.edit_row.edit_row_form_data;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.jboss.resteasy.annotations.cache.Cache;

import com.googlecode.afdbaccess.cache.preparedstatement.PreparedStatementArgumentsSetterHelper;
import com.googlecode.afdbaccess.config.injectconfig.ManagedRequestTransaction;
import com.googlecode.afdbaccess.web.common.db.converters.SimpleExtJsJsonResponseSingleRowConverter;
import com.googlecode.afdbaccess.web.common.interceptors.DatabaseAccessing;
import com.googlecode.afdbaccess.web.common.interceptors.RequestLogged;
import com.googlecode.afdbaccess.web.common.json.ExtJsJsonResponse;

@RolesAllowed("theRole")
@RequestLogged
@DatabaseAccessing
@Path("edit-row/edit-row-form-data")
public class EditRowGetRest {
    @Inject
    private ManagedRequestTransaction t;

    @GET
    @Cache(maxAge=0)
    @Path("{id}")
    @Produces("application/json")
    public ExtJsJsonResponse get(@SuppressWarnings("unused") @Context HttpServletRequest request, @PathParam("id") long id) throws Exception {
        String sql =
            "SELECT\n" +
            "  webTable.stringAttribute\n" +
            "FROM\n" +
            "  webTable\n" +
            "WHERE\n" +
            "  webTable.webTable_id = ?\n";

        PreparedStatementArgumentsSetterHelper setter = new PreparedStatementArgumentsSetterHelper();
        setter.addArgument(id);

        return t.executeQuery(sql, setter, SimpleExtJsJsonResponseSingleRowConverter.class, 0);
    }
}
